package pkg.chemdrm;

import java.util.Collection;

public class HealthEvent implements Event {
	int mX, mY; // location of event
	int mValue; // the damage/heal value (i.e. the amount to change the health by)
	
	public final static int HEALTH_EVENT_TYPE_UNKNOWN = 0;
	public final static int HEALTH_EVENT_TYPE_AI = 1; // heal AI
	public final static int HEALTH_EVENT_TYPE_HUMAN = 2; // heal human
	
	int mType = HEALTH_EVENT_TYPE_UNKNOWN; // the type of person this is meant to damage.
	
	
	int mRange; // radius of the event
	
	public HealthEvent(int pX, int pY, int pRange, int pType, int pValue)
	{
		mValue = pValue;
		mX = pX;
		mY = pY;
		mType = pType;
		mRange = pRange;
	}
	
	public void executeOnListeners(Collection<EventListener> pListeners)
	{
		for(EventListener p : pListeners)
		{
			if(p instanceof Player)
			{
				Player pp = (Player) p;
				
				// check if player is in range
				if(Math.sqrt(Math.pow(pp.getX() - mX, 2) + Math.pow(pp.getY() - mY, 2)) <= mRange)
				{
					((Player) p).changeHealthBy(mValue);

				}	
			}
		}
		
	}

}
